package com.bottle.init;

import com.alibaba.fastjson.JSONObject;
import com.bottle.client.OkHttpRequestUtils;
import com.bottle.client.PollingClient;
import com.bottle.mode.ReJson;
import com.bottle.mode.UserInfo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

/**
 * @author: chenyuncong
 * @Date: 2020/5/8 17:56
 */
@Configuration
public class InitClient {

    @Value("${bottle.server.url}")
    private String url;

    @PostConstruct
    public void init() throws Exception {
        Map<String, UserInfo> map = new HashMap<>();
        String json = null;
        UserInfo userInfo=null;
        for (int i = 0; i < 10; i++) {
            json = OkHttpRequestUtils.doGet(url + "test/getUserByAccount?account=admin"+i);
            JSONObject  reJson= JSONObject.parseObject(json);
            userInfo = JSONObject.parseObject(reJson.getString("data"),UserInfo.class);
            map.put(userInfo.getUserId(),userInfo);
        }

    }

    @Bean
    public PollingClient getPollingClient() {
        return new PollingClient();
    }


}
